package cn.edu.ljl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

//添加具体学科的信息


//已经不使用


//使用judge

//public class addExperience extends HttpServlet {
//    private static final String INSERT_TEMPLATE =
//            "INSERT INTO courses (`nam`, `course`, `advice`) " +
//                    "VALUES ('%s', '%s', '%s')";

public class addExperience extends HttpServlet {
    private static final String INSERT_TEMPLATE =
            "INSERT INTO courses (`nam`, `course`, `advice`) " +
                    "VALUES ('%s', '%s', '%s')";

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String name = request.getParameter("nam");
        String course = request.getParameter("course");
        String advice = request.getParameter("advice");

        String sql = String.format(INSERT_TEMPLATE, name, course, advice);
        System.out.println(sql);


        try {
            DBMS.insert(sql);
            response.sendRedirect("./listExperience");
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
